package xyz.scootaloo.oj.leetcode

import org.junit.Test
import xyz.scootaloo.common.TestDsl

/**
 * @author flutterdash@qq.com
 * @since 2021/7/4 15:02
 */
class P167 : TestDsl {

    private fun twoSum(numbers: IntArray, target: Int): IntArray {
        val size = numbers.size
        for (i in 0 until (size - 1)) {
            val value = numbers[i]
            val lack = target - value
            val idx = numbers.binarySearch(lack, i + 1, size)
            if (idx > 0) {
                return intArrayOf(i + 1, idx + 1)
            }
        }

        return intArrayOf()
    }

    @Test
    fun test0() {
        twoSum(intArrayOf(2, 7, 11, 15), 9).log()
        twoSum(intArrayOf(2, 7, 11, 15), 26).log()
    }

}
